package grdnlog.bean;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Id;

import org.springframework.social.connect.ConnectionData;

@Entity
public class AppEngineConnectionData implements Serializable {

	private static final long serialVersionUID = 5637891475525691007L;

	@Id
    private String id;
	
	@Basic
	private String userId;
	
	@Basic
	private String providerId;
	
	@Basic
	private String providerUserId;
	
	@Basic
	private String displayName;
	
	@Basic
	private String profileUrl;
	
	@Basic
	private String imageUrl;
	
	@Basic
	private String accessToken;
	
	@Basic
	private String secret;
	
	@Basic
	private String refreshToken;
	
	@Basic
	private Long expireTime;
	
	@Basic
	private Long rank;

	public AppEngineConnectionData() {
		
	}
	
	public ConnectionData getConnectionData() {
		return new ConnectionData(accessToken, accessToken, accessToken, accessToken, accessToken, accessToken, accessToken, accessToken, expireTime);
	}

	public String getProviderId() {
		return providerId;
	}

	public void setProviderId(String providerId) {
		this.providerId = providerId;
		updateKey();
	}

	public String getProviderUserId() {
		return providerUserId;
	}

	public void setProviderUserId(String providerUserId) {
		this.providerUserId = providerUserId;
		updateKey();
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public String getProfileUrl() {
		return profileUrl;
	}

	public void setProfileUrl(String profileUrl) {
		this.profileUrl = profileUrl;
	}

	public String getImageUrl() {
		return imageUrl;
	}

	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}

	public String getAccessToken() {
		return accessToken;
	}

	public void setAccessToken(String accessToken) {
		this.accessToken = accessToken;
	}

	public String getSecret() {
		return secret;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}

	public String getRefreshToken() {
		return refreshToken;
	}

	public void setRefreshToken(String refreshToken) {
		this.refreshToken = refreshToken;
	}

	public Long getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(Long expireTime) {
		this.expireTime = expireTime;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
		updateKey();
	}

	public Long getRank() {
		return rank;
	}

	public void setRank(Long rank) {
		this.rank = rank;
	}

	private void updateKey() {
		StringBuilder builder = new StringBuilder();
		builder.append(this.userId).append("-");
		builder.append(this.providerId).append("-");
		builder.append(this.providerUserId);
		
		this.id = builder.toString();
	}
	
}
